<template>
    <div>
        <div class="item-box" v-for="(item, index) in list" :key="index" :class="{'active' : index === current}"  @click="selectMaterial(index)">
            <div class="header">
                <span class="name">{{ item.name }}</span>
                <span class="no">|</span>
                <span class="code">{{ item.code }}</span>
            </div>
            <div class="content">
                <div class="line flex">
                    <div class="info">
                        <span class="name">物料单位:</span>
                        <span class="val">{{ item.comp }}</span>
                    </div>
                    <div class="info">
                        <span class="name">物料规格:</span>
                        <span class="val">{{ item.standard }}</span>
                    </div>
                </div>
                <div class="line flex">
                    <div class="info">
                        <span class="name">物料类型:</span>
                        <span class="val">{{ item.typeName }}</span>
                    </div>
                    <div class="info">
                        <span class="name">物料分类:</span>
                        <span class="val">{{ item.sortName }}</span>
                    </div>
                </div>
                <div class="line">
                    <div class="info">
                        <span class="name">物料备注:</span>
                        <span class="val">{{ item.remark }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
// import MaterialContent from "./MaterialContent.vue";
export default {
  name: 'ListItem',
  components: {
    // MaterialContent,
  },
  props: {
    list: {
      type: Array,
      default: () => [],
      required: true
    }
  },
    data() {
        return {
            current: null,
        // isShow: false,
        }
    },
    methods: {
        selectMaterial(index) {
            // this.isShow = true;
            this.current = index
            this.$emit('selectMaterial', this.list[index])
        }
    }
  
}
</script>

<style lang="scss" scoped>
.item-box{
    margin: 0 0 12px;
    background-color: #ffffff;
    border-radius: 4px;
    box-shadow: 0px 3px 6px 1px rgba(0,0,0,0.16);
    padding: 12px;
    font-size: 14px;
    color: #333333;
    border: 1px #ffffff solid;
    &.active{
        border: 1px #548AF1 solid;
        position: relative;
        &::after{
            content: '';
            width: 4px;
            height: 100%;
            background-color: #548AF1;
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
        }
    }
    .header{
        .no{
            margin: 0 4px;
        }
    }
    .content{
        padding-top: 5px;
        .line{
            margin-top: 10px;
            .name{
                color: #666666;
            }
        }
        .flex{
            display: flex;
            justify-content: space-between;

        }
    }
}
</style>